package com.java1412.utils;

import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * 生成验证码的工具类
 *
 * @author java1412
 * @since 2023-06-21 11:42:47
 */
@Component
public class GenerateCodeUtil {

    /**
     * 生成四位验证码
     */
    public String generateVerifyCode() {
//        String s = UUID.randomUUID().toString();
//        String code = s.substring(s.length() - 4);
//        return code;
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 4; i++) {
            int code = (int) (Math.random() * 10);
            sb.append(code);
        }
        return sb.toString();
    }
}
